<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>binlog-protocol | YouN 科技温度</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="binlog protocol" />
  
  
  
  
  <meta name="description" content="生成新的binlog1flush logs;  清空binlog1reset master;    格式Binlog files start with a Binlog File Header followed by a series of Binlog Event Header + Event + Event + Event Header A binlog file starts with a">
<meta property="og:type" content="article">
<meta property="og:title" content="binlog-protocol">
<meta property="og:url" content="http://this4u.cn/2020/06/02/binlog-protocol/index.html">
<meta property="og:site_name" content="YouN 科技温度">
<meta property="og:description" content="生成新的binlog1flush logs;  清空binlog1reset master;    格式Binlog files start with a Binlog File Header followed by a series of Binlog Event Header + Event + Event + Event Header A binlog file starts with a">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-06-02T06:58:21.000Z">
<meta property="article:modified_time" content="2023-04-13T05:58:10.684Z">
<meta property="article:author" content="Timmy">
<meta property="article:tag" content="binlog protocol">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="YouN 科技温度" type="application/atom+xml">
  
  <link rel="icon" href="/css/images/favicon.ico">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
    
  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz%3A200%2C300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">

  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Oswald%3A300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">
  
<link rel="stylesheet" href="/css/style.css">


  
<script src="/js/jquery-3.1.1.min.js"></script>


  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css" >
  <link rel="stylesheet" href="/css/fashion.css" >
  <link rel="stylesheet" href="/css/glyphs.css" >

<meta name="generator" content="Hexo 6.3.0"></head>



  <body data-spy="scroll" data-target="#toc" data-offset="50">


  


<header id="allheader" class="site-header" role="banner" 
   >
  <div class="clearfix container">
      <div class="site-branding">

          <h1 class="site-title">
            
              <a href="/" rel="home" >
                <img style="margin-bottom: 2px;"  width="126px" height="60px" alt="Hike News" src=" /css/images/youu.jpg">
              </a>
            
          </h1>
          
          
            
          <nav id="main-navigation" class="main-navigation" role="navigation">
            <a class="nav-open">Menu</a>
            <a class="nav-close">Close</a>

            <div class="clearfix sf-menu">
              <ul id="main-nav" class="menu sf-js-enabled sf-arrows"  style="touch-action: pan-y;">
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="/"> <a class="" href="/">首页</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="archives"> <a class="" href="/archives">归档</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="categories"> <a class="" href="/categories">分类</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="tags"> <a class="" href="/tags">标签</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="about"> <a class="" href="/about">关于</a> </li>
                    
              </ul>
            </div>
          </nav>

      </div>
  </div>
</header>


  <div id="container">
    <div id="wrap">
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-binlog-protocol" style="width: 66%; float:left;" class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" class="article-title" itemprop="name">
      binlog-protocol
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/06/02/binlog-protocol/" class="article-date">
	  <time datetime="2020-06-02T06:58:21.000Z" itemprop="datePublished">六月 2, 2020</time>
	</a>

       
      
	<span id="busuanzi_container_page_pv">
	  本文总阅读量<span id="busuanzi_value_page_pv"></span>次
	</span>

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="生成新的binlog"><a href="#生成新的binlog" class="headerlink" title="生成新的binlog"></a>生成新的binlog</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush logs;</span><br></pre></td></tr></table></figure>

<h2 id="清空binlog"><a href="#清空binlog" class="headerlink" title="清空binlog"></a>清空binlog</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">reset master;</span><br></pre></td></tr></table></figure>



<h2 id="格式"><a href="#格式" class="headerlink" title="格式"></a>格式</h2><p>Binlog files start with a <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-file-header.html">Binlog File Header</a> followed by a series of <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-event.html">Binlog Event</a></p>
<p>Header + Event + Event + Event</p>
<p><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-file-header.html">Header</a></p>
<p>A binlog file starts with a <code>Binlog File Header</code> <code>[ fe &#39;bin&#39; ]</code></p>
<h2 id="Event"><a href="#Event" class="headerlink" title="Event"></a>Event</h2><p>EventHeader + Event</p>
<h4 id="Binlog-Event-header"><a href="#Binlog-Event-header" class="headerlink" title="Binlog Event header"></a>Binlog Event header</h4><p>The binlog event header starts each event and is either 13 or 19 bytes long, depending on the <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-version.html">binlog version</a>.</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">4              timestamp</span><br><span class="line">1              event type</span><br><span class="line">4              server-id</span><br><span class="line">4              event-size</span><br><span class="line">   if binlog-version &gt; 1:</span><br><span class="line">4              log pos</span><br><span class="line">2              flags</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">+---------+---------+---------+------------+-------------+-------+</span><br><span class="line">|timestamp|type code|server_id|event_length|next_position|flags  |</span><br><span class="line">|4 bytes  |1 byte   |4 bytes  |4 bytes     |4 bytes      |2 bytes|</span><br><span class="line">+---------+---------+---------+------------+-------------+-------+</span><br></pre></td></tr></table></figure>



<p><strong>Fields</strong></p>
<ul>
<li><strong>timestamp</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-4"><em>4</em></a>) – seconds since unix epoch</li>
<li><strong>event_type</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-1"><em>1</em></a>) – see <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-event-type.html">Binlog Event Type</a></li>
<li><strong>server_id</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-4"><em>4</em></a>) – server-id of the originating mysql-server. Used to filter out events in circular replication.</li>
<li><strong>event_size</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-4"><em>4</em></a>) – size of the event (header, post-header, body)</li>
<li><strong>log_pos</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-4"><em>4</em></a>) – position of the next event</li>
<li><strong>flags</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-2"><em>2</em></a>) – see <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-event-flag.html">Binlog Event Flag</a></li>
</ul>
<p><strong>Table 14.5 Binlog Versions</strong></p>
<table>
<thead>
<tr>
<th>Binlog version</th>
<th>MySQL Version</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>MySQL 3.23 - &lt; 4.0.0</td>
</tr>
<tr>
<td>2</td>
<td>MySQL 4.0.0 - 4.0.1</td>
</tr>
<tr>
<td>3</td>
<td>MySQL 4.0.2 - &lt; 5.0.0</td>
</tr>
<tr>
<td>4</td>
<td>MySQL 5.0.0+</td>
</tr>
</tbody></table>
<p>目前市面上都是V4了，故EventHeader的长度可以默认为19</p>
<p><strong>Binlog::FORMAT_DESCRIPTION_EVENT:</strong></p>
<p>FORMAT_DESCRIPTION_EVENT 是binlog文件的第一个 Event</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//https://sourcegraph.com/github.com/mysql/mysql-server/-/blob/libbinlogevents/src/binlog_event.cpp#L84:1</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   The method returns the checksum algorithm used to checksum the binary log.</span></span><br><span class="line"><span class="comment">   For MySQL server versions &lt; 5.6, the algorithm is undefined. For the higher</span></span><br><span class="line"><span class="comment">   versions, the type is decoded from the FORMAT_DESCRIPTION_EVENT.</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">   @param buf buffer holding serialized FD event</span></span><br><span class="line"><span class="comment">   @param len netto (possible checksum is stripped off) length of the event buf</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">   @return  the version-safe checksum alg descriptor where zero</span></span><br><span class="line"><span class="comment">            designates no checksum, 255 - the orginator is</span></span><br><span class="line"><span class="comment">            checksum-unaware (effectively no checksum) and the actuall</span></span><br><span class="line"><span class="comment">            [1-254] range alg descriptor.</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function">enum_binlog_checksum_alg <span class="title">Log_event_footer::get_checksum_alg</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *buf,</span></span></span><br><span class="line"><span class="params"><span class="function">                                                            <span class="type">unsigned</span> <span class="type">long</span> len)</span> </span>&#123;</span><br><span class="line">  <span class="built_in">BAPI_ENTER</span>(<span class="string">&quot;Log_event_footer::get_checksum_alg(const char*, unsigned long)&quot;</span>);</span><br><span class="line">  enum_binlog_checksum_alg ret = BINLOG_CHECKSUM_ALG_UNDEF;</span><br><span class="line">  <span class="type">char</span> version[ST_SERVER_VER_LEN];</span><br><span class="line">  <span class="type">unsigned</span> <span class="type">char</span> version_split[<span class="number">3</span>];</span><br><span class="line">  <span class="built_in">BAPI_ASSERT</span>(buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT);</span><br><span class="line">  <span class="keyword">if</span> (len &gt; LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET + <span class="number">1</span>) &#123;</span><br><span class="line">    <span class="type">uint8_t</span> common_header_len =</span><br><span class="line">        buf[LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET];</span><br><span class="line">    <span class="keyword">if</span> (len &gt;=</span><br><span class="line">        <span class="built_in">static_cast</span>&lt;<span class="type">unsigned</span> <span class="type">long</span>&gt;(common_header_len + ST_SERVER_VER_OFFSET +</span><br><span class="line">                                   ST_SERVER_VER_LEN)) &#123;</span><br><span class="line">      <span class="built_in">memcpy</span>(version, buf + common_header_len + ST_SERVER_VER_OFFSET,</span><br><span class="line">             ST_SERVER_VER_LEN);</span><br><span class="line">      version[ST_SERVER_VER_LEN - <span class="number">1</span>] = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">      <span class="built_in">do_server_version_split</span>(version, version_split);</span><br><span class="line">      <span class="keyword">if</span> (<span class="built_in">version_product</span>(version_split) &lt; checksum_version_product)</span><br><span class="line">        ret = BINLOG_CHECKSUM_ALG_UNDEF;</span><br><span class="line">      <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="type">size_t</span> checksum_alg_offset =</span><br><span class="line">            len - (BINLOG_CHECKSUM_ALG_DESC_LEN + BINLOG_CHECKSUM_LEN);</span><br><span class="line">        ret =</span><br><span class="line">            <span class="built_in">static_cast</span>&lt;enum_binlog_checksum_alg&gt;(*(buf + checksum_alg_offset));</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="built_in">BAPI_RETURN</span>(ret);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<blockquote>
<p>A format description event is the first event of a binlog for binlog-version 4. It describes how the other events are layed out.</p>
</blockquote>
<p><strong>Row Based Replication Events</strong></p>
<p>In Row Based replication the changed rows are sent to the slave which removes side-effects and makes it more reliable. Now all statements can be sent with RBR though. Most of the time you will see RBR and SBR side by side.</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/table-map-event.html">TABLE_MAP_EVENT</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#delete-rows-eventv0">DELETE_ROWS_EVENTv0</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#update-rows-eventv0">UPDATE_ROWS_EVENTv0</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#write-rows-eventv0">WRITE_ROWS_EVENTv0</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#delete-rows-eventv1">DELETE_ROWS_EVENTv1</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#update-rows-eventv1">UPDATE_ROWS_EVENTv1</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#write-rows-eventv1">WRITE_ROWS_EVENTv1</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#delete-rows-eventv2">DELETE_ROWS_EVENTv2</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#update-rows-eventv2">UPDATE_ROWS_EVENTv2</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#write-rows-eventv2">WRITE_ROWS_EVENTv2</a></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">00000004  87 77 d4 5e|0f|01 00 00  00|79 00 00 00|7d 00 00  |.w.^.....y...&#125;..|</span><br><span class="line">00000014  00|00 00|04 00|38 2e 30  2e 32 30 00 00 00 00 00  |.....8.0.20.....|</span><br><span class="line">00000024  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|</span><br><span class="line">00000034  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|</span><br><span class="line">00000044  00 00 00 00 00 00 00|87  77 d4 5e|13|00 0d 00 08  |........w.^.....|</span><br><span class="line">00000054  00 00 00 00 04 00 04 00  00 00|61|00 04 1a 08 00  |..........a.....|</span><br><span class="line">00000064  00 00 08 08 08 02 00 00  00 0a 0a 0a 2a 2a 00 12  |............**..|</span><br><span class="line">00000074  34 00 0a 28|01|63 c8 ff  8b                       |4..(.c....w.^#..|</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>Event Header</strong></p>
<blockquote>
<p>timestamp:	87 77 d4 5e  #1590982535</p>
<p>event type:	0f  # <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/format-description-event.html">FORMAT_DESCRIPTION_EVENT</a></p>
<p>server-id:	01 00 00  00  #1</p>
<p>event-size:	79 00 00 00     #121</p>
<p>log pos:	7d 00 00 00	#125 position of the next event</p>
<p>flag:	00 00	#0</p>
</blockquote>
<p><strong>Event Body</strong> (FORMAT_DESCRIPTION_EVENT)</p>
<blockquote>
<p>binlog-version:	04 00	#4</p>
<p>mysql-server version:	38 2e 30  2e 32 30 00 00 00 00 00 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00	#8.0.20</p>
<p>create timestamp:	87 77 d4 5e	#1590982535</p>
<p>event header length:	13	#19 固定值</p>
<p>event type header lengths：	00 0d 00 08 00 00 00 00 04 00 04 00  00 00	# 长度(15-1)</p>
<p>data length:	61	#97   &#x3D;&#x3D;&gt; #check sum block &#x3D; event-size - event header length - data length &#x3D; 121-19-97 &#x3D; 5</p>
<p>skip:	121(eventSize)-19(header)-2(binlogVersion)-50(serverVersion)-4(time)-1(headerLength)-14(typeHeaderLength)-1(dataLength)-5(checkSumBlock) &#x3D; 25</p>
<p>check sum type:	01 #1 CRC32</p>
</blockquote>
<p>例如：<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/table-map-event.html">TABLE_MAP_EVENT</a></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">post-header:</span><br><span class="line">    if post_header_len == 6 &#123;</span><br><span class="line">  4              table id</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">  6              table id</span><br><span class="line">    &#125;</span><br><span class="line">  2              flags</span><br><span class="line"></span><br><span class="line">payload:</span><br><span class="line">  1              schema name length</span><br><span class="line">  string         schema name</span><br><span class="line">  1              [00]</span><br><span class="line">  1              table name length</span><br><span class="line">  string         table name</span><br><span class="line">  1              [00]</span><br><span class="line">  lenenc-int     column-count</span><br><span class="line">  string.var_len [length=$column-count] column-def</span><br><span class="line">  lenenc-str     column-meta-def</span><br><span class="line">  n              NULL-bitmask, length: (column-count + 8) / 7</span><br></pre></td></tr></table></figure>



<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">+=====================================+</span><br><span class="line">|        | fixed part (post-header)   |</span><br><span class="line">| data   +----------------------------+</span><br><span class="line">|        | variable part (payload)    |</span><br><span class="line">+=====================================+</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-file.html">参考</a></p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/binlog-protocol/" rel="tag">binlog protocol</a></li></ul>

      
        
	<div id="comment">
		<!-- 来必力City版安装代码 -->
		<div id="lv-container" data-id="city" data-uid="MTAyMC8yOTQ4MS82MDQ5">
		<script type="text/javascript">
		   (function(d, s) {
		       var j, e = d.getElementsByTagName(s)[0];

		       if (typeof LivereTower === 'function') { return; }

		       j = d.createElement(s);
		       j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
		       j.async = true;

		       e.parentNode.insertBefore(j, e);
		   })(document, 'script');
		</script>
		<noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
		</div>
		<!-- City版安装代码已完成 -->
	</div>



      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2020/06/15/mysql-xa/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">上一篇</strong>
      <div class="article-nav-title">
        
          mysql-xa
        
      </div>
    </a>
  
  
    <a href="/2020/06/02/mysql-server/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">下一篇</strong>
      <div class="article-nav-title">mysql-server</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录</strong>
    
      <ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%94%9F%E6%88%90%E6%96%B0%E7%9A%84binlog"><span class="nav-number">1.</span> <span class="nav-text">生成新的binlog</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B8%85%E7%A9%BAbinlog"><span class="nav-number">2.</span> <span class="nav-text">清空binlog</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A0%BC%E5%BC%8F"><span class="nav-number">3.</span> <span class="nav-text">格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Event"><span class="nav-number">4.</span> <span class="nav-text">Event</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Binlog-Event-header"><span class="nav-number">4.0.1.</span> <span class="nav-text">Binlog Event header</span></a></li></ol></li></ol></li></ol>
    
    </div>
  </aside>
</section>
        
      </div>

    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    <footer id="footer" class="site-footer">
  

  <div class="clearfix container">
      <div class="site-info">
		<a href="https://beian.miit.gov.cn/" target="_blank">鄂ICP备2023005434号-1</a>  	
	        Copyright &copy; 2023 YouN 科技温度 All Rights Reserved.
        
            <span id="busuanzi_container_site_uv">
              本站访客数<span id="busuanzi_value_site_uv"></span>人次  
              本站总访问量<span id="busuanzi_value_site_pv"></span>次
            </span>
          
      </div>
      <div class="site-credit">
        Theme by <a href="https://github.com/iTimeTraveler/hexo-theme-hipaper" target="_blank">hipaper</a>
      </div>
  </div>
</footer>


<!-- min height -->

<script>
    var wrapdiv = document.getElementById("wrap");
    var contentdiv = document.getElementById("content");

    wrapdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";
    contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";


    <!-- headerblur min height -->
    
    
</script>

    
<div style="display: none;">
  <script src="https://s11.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
</div>

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>


<script src="/js/bootstrap.js"></script>


<script src="/js/main.js"></script>








  <div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js" async=""></script>
</body>
</html>
